<?php

namespace App\Models\Traits;

use Encore\Admin\Facades\Admin;
use Illuminate\Support\Facades\DB;

trait VendorTrait
{
	public function createAdminAccount()
	{
		DB::transaction(function () {
			$this->initial_code = uniqid(); // initial password of vendor.
			$this->save();
			
			$vendorAdmin = Admin::user()->create([
				'username' => $this->phone, // username for auth.
				'name' => $this->name,  // name for display.
				'password' => bcrypt($this->initial_code),
			]);
			$vendorAdmin->roles()->attach(6);
		});
	}
}
